package edu.mercer.sse.error;

import com.google.common.base.Throwables;

import edu.mercer.sse.annotations.Fulfills;
import edu.mercer.sse.configuration.Config;
import edu.mercer.sse.log.LoggerCustom;

/**
 * Log exception.<p>
 *
 * @see ErrorLogging
 */

public class ErrorLoggingVisitor implements ErrorLogging<String, Throwable>
{
	private final Boolean _verbose = Config.factory()
										   .load()
	  			 						   .get("VERBOSE")
	  			 						   .equalsIgnoreCase("true");
	
	@Fulfills("ErrorLogging")
	public String visit( final Throwable err ) 
	{
		final String errorMsg = err + "" + Throwables
				.getStackTraceAsString(err);
		
		if( _verbose ) System.err.println( errorMsg );
		
		LoggerCustom.obtainLog( "errors" ).severe( errorMsg );
		
		return errorMsg;
	
	}//method


}//class